Skip to content

8386546: Fix race when reserving memory with NUMA interleaving on Windows - #31507

Closed
roberttoyonaga wants to merge 3 commits into
openjdk:masterfrom
roberttoyonaga:VA2-part2
Closed

roberttoyonaga wants to merge 3 commits into
openjdk:masterfrom
roberttoyonaga:VA2-part2

Conversation

@roberttoyonaga

@roberttoyonaga roberttoyonaga commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Previously on Windows Hotspot used the following race-y pattern to reserve a virtual memory region and divide it up among NUMA nodes:

  • Reserve a large region in order to get an available address range.
  • Release the entire range
  • Quickly re-reserve subregions within the original region (assigning each to a round robin of NUMA nodes).
    See allocate_pages_individually.

VirtualAlloc2 (available since Windows version 1803) removes the need for this race-y code by introducing "placeholders". Placeholders allow for reserving regions, and later splitting them up while still holding the reservation.

This is a scoped-down version of JDK-8376561 and #30270 limited to the changes required to eliminate the NUMA race. This is the 2nd change in a series of changes that take advantage of VirtualAlloc2 to replace races in Windows code. The preceding change was JDK-8385586.

Divergences from JDK-8376561 / #30270 :

  1. The os:: Placeholder API has been moved into os::win32:: in order to constrain the scope of changes to Windows code only.
  2. Tests have been moved from test_os.cpp to test_os_windows.cpp

Notes

reserve_placeholder_memory, split_memory, and convert_to_reserved could have been made internal helper functions in os_windows.cpp. However, I added them to os::win32:: so that they could be more thoroughly unit tested.

Testing:

  • Added new tests to os_windows.cpp
  • make test TEST=gtest:os_windows.placeholder_numa_reserve_commit GTEST="VM_OPTIONS=-XX:+UseNUMAInterleaving"
  • make test TEST=gtest:os
  • Tier 1

Tested locally on Windows with multiple NUMA nodes and also without multiple NUMA nodes.



Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8386546: Fix race when reserving memory with NUMA interleaving on Windows (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/31507/head:pull/31507
$ git checkout pull/31507

Update a local copy of the PR:
$ git checkout pull/31507
$ git pull https://git.openjdk.org/jdk.git pull/31507/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 31507

View PR using the GUI difftool:
$ git pr show -t 31507

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/31507.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Jun 12, 2026

Copy link
Copy Markdown

👋 Welcome back roberttoyonaga! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Jun 12, 2026

Copy link
Copy Markdown

@roberttoyonaga This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8386546: Fix race when reserving memory with NUMA interleaving on Windows

Reviewed-by: asmehra, stuefe

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 245 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@ashu-mehra, @tstuefe) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk Bot changed the title 8386546 8386546: Fix race when reserving memory with NUMA interleaving on Windows Jun 12, 2026
@openjdk

openjdk Bot commented Jun 12, 2026

Copy link
Copy Markdown

@roberttoyonaga The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk

openjdk Bot commented Jun 12, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-runtime. This can be overridden with the /reviewers command.

@roberttoyonaga
roberttoyonaga marked this pull request as ready for review June 15, 2026 20:03
@openjdk openjdk Bot added the rfr Pull request is ready for review label Jun 15, 2026
@mlbridge

mlbridge Bot commented Jun 15, 2026

Copy link
Copy Markdown

Webrevs

@johan-sjolen

Copy link
Copy Markdown
Contributor

Hi Robert, I intend to review this as well, but it'll have to wait until next week.

Comment thread src/hotspot/os/windows/os_windows.cpp Outdated
char* os::win32::convert_to_reserved(PlaceholderRegion region, int numa_node) {
guarantee(is_VirtualAlloc2_supported(), "convert_to_reserved requires VirtualAlloc2");
assert(!region.is_empty(), "Region cannot be empty");
assert(is_aligned(region.base(), os::vm_page_size()), "Region base should be page-aligned");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the region.base() be aligned to allocation granularity as it is passed to VirtualAlloc2 which expects BaseAddress to be a multiple of the system allocation granularity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a good point. I have updated it to assert(is_aligned(region.size(), os::vm_allocation_granularity())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, if the PlaceholderRegion's base should be aligned to allocation granularity, then shouldn't split_memory require that the offset be also aligned to allocation granularity? After all, the PlaceholderRegion's base depends on the offset provided split_memory.
I also wonder if we should move this assert to Placeholder's constructor, because it looks like the base must always be aligned to allocation granularity.

@roberttoyonaga roberttoyonaga Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. I've moved the asserts into the Placeholder constructor.
However, offset doesn't always need to be aligned to allocation granularity. For example, at the end of reserve_with_numa_placeholder when the split consumes the entire remaining Placeholder region. But it's easy to handle this special case, then assert afterward.

reserveTimer.milliseconds(), reserveTimer.ticks());
bool use_numa_interleaving = (UseNUMAInterleaving && !UseLargePages);
if (use_numa_interleaving) {
if (is_VirtualAlloc2_supported()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block should be inside reserveTimer() scope, like:

elapsedTime reserveTimer;
if (is_VirtualAlloc2_supported()) {
  ...
} else {
  ...
}
if (Verbose && Print...) {
  ...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right. I have widened the scope of the timer. Thanks!

// Double convert
char* reserved = os::win32::convert_to_reserved(region);
ASSERT_EQ(reserved, region.base());
reserved = os::win32::convert_to_reserved(region);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear what the double convert is expected to do. Would it fail silently or crash?

@roberttoyonaga roberttoyonaga Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should crash and produce the error text: "...Failed to convert placeholder...". I've added a comment there for clarity.

@ashu-mehra ashu-mehra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comments, lgtm

@roberttoyonaga

Copy link
Copy Markdown
Contributor Author

@tstuefe can you please have another look at this when you have time?
This is functionally just a subset of the changes in the original larger PR #30270. I needed to do a bit of refactoring as explained in the description above.

@tstuefe tstuefe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me too.

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Jul 14, 2026
@roberttoyonaga

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews!

/integrate

@openjdk

openjdk Bot commented Jul 15, 2026

Copy link
Copy Markdown

Going to push as commit 376ecc5.
Since your change was applied there have been 265 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Jul 15, 2026
@openjdk openjdk Bot closed this Jul 15, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 15, 2026
@openjdk

openjdk Bot commented Jul 15, 2026

Copy link
Copy Markdown

@roberttoyonaga Pushed as commit 376ecc5.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-runtime [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants